#include "SmartHomeMonitorServer.hpp"
#include "Configuration.hpp"
#include <unistd.h>
#include <string.h>
#include <iostream>
using std::cout;
using std::endl;
using namespace std;

int main()
{
    wd::Configuration *config=Configuration::getInstance();
    //先加载配置文件
    config->loadConfig("./conf/server.conf");
    //使用get()
    string portStr=config->get("port");
    string threadNumStr=config->get("thread_num");
    string taskNumStr=config->get("task_num");
    string ipStr=config->get("ip");
    //检查配置值是否有效
    if(portStr.empty()||threadNumStr.empty()||taskNumStr.empty())
    {
        cout<<"Error:Missing resquired configuaration items!"<<endl;
        return -1;
    }
    //转换为相应类型
    unsigned short port=static_cast<unsigned short>(atoi(portStr.c_str()));
    int threadNum=atoi(threadNumStr.c_str());
    int taskNum=atoi(taskNumStr.c_str());

    if(ipStr.empty())
    {
       ipStr="0.0.0.0";
    }

    //创建服务器实例
    SmartHomeMonitorServer server(port,ipStr,threadNum,taskNum);

    server.start();
        return 0;
}


